import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:sptapp/config/const.dart';
import 'package:sptapp/routes/route.dart';

PreferredSizeWidget myAppBar(BuildContext context,String text,
    {bool isLeading = true,
      List<Widget> actions = const [],
      Color backgroundColor = Colors.white,
      Widget? titleWidget,
      Widget? leadingWidget,
      bool isColor = false,
      Color fontColor = Colors.white
    }){
  return AppBar(
    backgroundColor: isColor ? backgroundColor : Colors.transparent,
    systemOverlayStyle: SystemUiOverlayStyle(
      statusBarColor: Colors.black,
      systemNavigationBarColor: Colors.black,
      statusBarBrightness: Brightness.dark,
    ),
    centerTitle: true,
    title: titleWidget ?? Text(text,style: TextStyle(
      color: fontColor,
      fontSize: 35.sp,
      fontWeight: FontWeight.w600
    ),),
    leading: leadingWidget?? Visibility(
      visible: isLeading,
      child: GestureDetector(
        onTap: (){
          Navigator.of(context).pop();
        },
        child: Icon(Icons.arrow_back_ios,color: fontColor,size: 40.w,),
      ),
    ),
    actions: actions,
  );
}


// 普通提示
void showToast(String text, [Map? position]) {

  Fluttertoast.showToast(
    msg: text,
    toastLength: Toast.LENGTH_SHORT,
    gravity: position == null ? ToastGravity.CENTER : position['gravity'],
    timeInSecForIosWeb: 1,
    backgroundColor: Color.fromRGBO(0, 0, 0, 0.8), // 灰色背景
    fontSize: 16.0,
  );
}

void showLoading(
    {String? status, EasyLoadingMaskType maskType = EasyLoadingMaskType.clear}) {
  EasyLoading.show(status: status, maskType: maskType);
}

void hideLoading() {
  EasyLoading.dismiss();
}

Widget myCustomAppBar(String text,{bool isLead = true}){
  return Container(
    child: Row(
      children: [
        Visibility(child: GestureDetector(
          onTap: (){
            Navigator.of(MyRoute.navigatorKey.currentContext!).pop();
          },
          child: Container(
            child: Image.asset('assets/login/back.png',width: 56.w,),
          ),
        ),visible: isLead,),
        SizedBox(width: 28.w,),
        Expanded(child: Container(
          child: Text(text,style: TextStyle(
              color: Colors.white,
              fontSize: 32.sp,
              fontWeight: FontWeight.w600
          ),maxLines: 1,overflow: TextOverflow.ellipsis,),
        ))
      ],
    ),
  );
}
Widget myCustomCenterTitleAppBar(String text,){
  return Container(
    child: Row(
      children: [
        GestureDetector(
          onTap: (){
            Navigator.of(MyRoute.navigatorKey.currentContext!).pop();
          },
          child: Container(
            child: Image.asset('assets/home/common_back.png',width: 48.w,),
          ),
        ),
        SizedBox(width: 28.w,),
        Expanded(child: Container(
          child: Text(text,style: TextStyle(
              color: Colors.white,
              fontSize: 32.sp,
              fontWeight: FontWeight.w600
          ),maxLines: 1,textAlign: TextAlign.center,overflow: TextOverflow.ellipsis,),
        )),
        SizedBox(width: 28.w + 48.w,),
      ],
    ),
  );
}
